package guet.dream.category;

import guet.dream.question.Question;

import java.util.HashSet;
import java.util.Set;

public class Category {
	private int categoryCode;
	private String name;
	private String description;
	private Category parentCategory;
	private Set<Category> childCategories = new HashSet<Category>();
	private Set<Question> questions = new HashSet<Question>();


	
	public Category() {}

	public Category(int categoryCode, String name, String description) {
		super();
		this.categoryCode = categoryCode;
		this.name = name;
		this.description = description;
	}








	public  int getCategoryCode() {
		return categoryCode;
	}




	public void setCategoryCode(int categoryCode) {
		this.categoryCode = categoryCode;
	}




	public String getName() {
		return name;
	}




	public void setName(String name) {
		this.name = name;
	}




	public String getDescription() {
		return description;
	}




	public void setDescription(String description) {
		this.description = description;
	}




	public Category getParentCategory() {
		return parentCategory;
	}




	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}




	public Set<Category> getChildCategories() {
		return childCategories;
	}




	public void setChildCategories(Set<Category> childCategories) {
		this.childCategories = childCategories;
	}




	public Set<Question> getQuestions() {
		return questions;
	}




	public void setQuestions(Set<Question> questions) {
		this.questions = questions;
	}




	public void addChildCategory(Category childCategory){
		if(childCategory == null){
			throw new IllegalArgumentException("Null child category:子类别集合为空值.");
		}
		//添加一个子类别,同时如果此子类别原来已经有父类别的话,从原来的父类别所有的子类别集合中删除
		if(childCategory.getParentCategory() != null){
			childCategory.getParentCategory().getChildCategories().remove(childCategory);
		}
		childCategory.setParentCategory(this);
		
		this.childCategories.add(childCategory);
	}
	
}
